{ Google Code Jam 2011. Qualification Round.
  Problemset: http://code.google.com/codejam/contest/dashboard?c=975485#
  Problem A.
  Verdict: Correct/Correct
}
uses SysUtils, Math;
var 
	i,n,j,t,k,r,ca,cb,pa,pb,cp:longint;
	ch:char;
	a,b,s:array[0..110] of longint;
begin
reset(input,'input.txt');
rewrite(output,'output.txt');
fillchar(a,sizeof(a),0);
fillchar(b,sizeof(B),0);
fillchar(s,sizeof(s),0);
read(t);
for i:=1 to t do begin
	a[0]:=0;
	b[0]:=0;
	read(n);
	for j:=1 to n do begin
		read(ch);
		read(ch);
		read(k);
		if ch='O' then begin
			inc(a[0]);
			a[a[0]]:=k;
			s[j]:=1;
		end else begin
			inc(b[0]);
			b[b[0]]:=k;
			s[j]:=2;
		end;
	end;
	r:=0;
	pa:=1;
	pb:=1;
	ca:=1;
	cb:=1;
	cp:=1;
	while cp<=n do begin
		inc(r);
		if (pa=a[ca]) and (s[cp]=1) then begin
			inc(ca);
			inc(cp);
			if cb<=b[0] then begin
				if pb<b[cb] then inc(pb) else
				if pb>b[cb] then dec(pb);
			end;
		end else
		if (pb=b[cb]) and (s[cp]=2) then begin
			inc(cb);
			inc(cp);
			if ca<=a[0] then begin
				if pa<a[ca] then inc(pa) else 
				if pa>a[ca] then dec(pa);
			end;
		end else begin
			if ca<=a[0] then begin
				if pa<a[ca] then inc(pa) else 
				if pa>a[ca] then dec(pa);
			end;
			if cb<=b[0] then begin
				if pb<b[cb] then inc(pb) else
				if pb>b[cb] then dec(pb);
			end;
		end;
	end;
	writeln('Case #',i,': ',r);
end;
end.